import 'dart:convert';

import 'package:emby/model/play_state.dart';

class SessionInfo {
  SessionInfo({
    this.playState,
    this.additionalUsers,
    this.remoteEndPoint,
    this.playableMediaTypes,
    this.playlistIndex,
    this.playlistLength,
    this.id,
    this.serverId,
    this.userId,
    this.userName,
    this.client,
    this.lastActivityDate,
    this.deviceName,
    this.deviceId,
    this.applicationVersion,
    this.supportedCommands,
    this.supportsRemoteControl,
  });

  PlayState playState;
  List<dynamic> additionalUsers;
  String remoteEndPoint;
  List<dynamic> playableMediaTypes;
  int playlistIndex;
  int playlistLength;
  String id;
  String serverId;
  String userId;
  String userName;
  String client;
  DateTime lastActivityDate;
  String deviceName;
  String deviceId;
  String applicationVersion;
  List<dynamic> supportedCommands;
  bool supportsRemoteControl;

  factory SessionInfo.fromRawJson(String str) => SessionInfo.fromJson(json.decode(str));

  String toRawJson() => json.encode(toJson());

  factory SessionInfo.fromJson(Map<String, dynamic> json) => SessionInfo(
        playState: PlayState.fromJson(json["PlayState"]),
        additionalUsers: List<dynamic>.from(json["AdditionalUsers"].map((x) => x)),
        remoteEndPoint: json["RemoteEndPoint"],
        playableMediaTypes: List<dynamic>.from(json["PlayableMediaTypes"].map((x) => x)),
        playlistIndex: json["PlaylistIndex"],
        playlistLength: json["PlaylistLength"],
        id: json["Id"],
        serverId: json["ServerId"],
        userId: json["UserId"],
        userName: json["UserName"],
        client: json["Client"],
        lastActivityDate: DateTime.parse(json["LastActivityDate"]),
        deviceName: json["DeviceName"],
        deviceId: json["DeviceId"],
        applicationVersion: json["ApplicationVersion"],
        supportedCommands: List<dynamic>.from(json["SupportedCommands"].map((x) => x)),
        supportsRemoteControl: json["SupportsRemoteControl"],
      );

  Map<String, dynamic> toJson() => {
        "PlayState": playState.toJson(),
        "AdditionalUsers": List<dynamic>.from(additionalUsers.map((x) => x)),
        "RemoteEndPoint": remoteEndPoint,
        "PlayableMediaTypes": List<dynamic>.from(playableMediaTypes.map((x) => x)),
        "PlaylistIndex": playlistIndex,
        "PlaylistLength": playlistLength,
        "Id": id,
        "ServerId": serverId,
        "UserId": userId,
        "UserName": userName,
        "Client": client,
        "LastActivityDate": lastActivityDate.toIso8601String(),
        "DeviceName": deviceName,
        "DeviceId": deviceId,
        "ApplicationVersion": applicationVersion,
        "SupportedCommands": List<dynamic>.from(supportedCommands.map((x) => x)),
        "SupportsRemoteControl": supportsRemoteControl,
      };
}
